package org.xmdl.silk.wrap;

import org.eclipse.emf.ecore.EClass;
import org.xmdl.silk.Assignment;
import org.xmdl.silk.Expression;
import org.xmdl.silk.Invocation;
import org.xmdl.silk.Literal;
import org.xmdl.silk.Method;
import org.xmdl.silk.NumDouble;
import org.xmdl.silk.NumInteger;
import org.xmdl.silk.Operation;
import org.xmdl.silk.ParaGroup;
import org.xmdl.silk.PrintStatement;
import org.xmdl.silk.Program;
import org.xmdl.silk.ReturnStatement;
import org.xmdl.silk.SilkPackage;
import org.xmdl.silk.Statement;
import org.xmdl.silk.ValueItem;
import org.xmdl.silk.Variable;
import org.xmdl.silk.VariableRef;

public class WrapUtils {

	public static Expression expression(Expression e) {
		Expression cw = null;
		EClass eClass = e.eClass();
		int classifierID = eClass.getClassifierID();
		switch (classifierID) {
		case SilkPackage.OPERATION:
			cw = new OperationWrap((Operation) e);
			break;
		case SilkPackage.NUM_INTEGER:
			cw = new NumIntegerWrap((NumInteger) e);
			break;
		case SilkPackage.NUM_DOUBLE:
			cw = new NumDoubleWrap((NumDouble) e);
			break;
		case SilkPackage.PARA_GROUP:
			cw = new ParaGroupWrap((ParaGroup) e);
			break;
		case SilkPackage.VARIABLE_REF:
			cw = new VariableRefWrap((VariableRef) e);
			break;
		case SilkPackage.INVOCATION:
			cw = new InvocationWrap((Invocation) e);
			break;
		default:
			break;
		}
		return cw;
	}

	public static Statement statement(Statement e) {
		StatementWrap sw = null;
		EClass eClass = e.eClass();
		int classifierID = eClass.getClassifierID();
		switch (classifierID) {
		case SilkPackage.ASSIGNMENT:
			sw = new AssignmentWrap((Assignment) e);
			break;
		case SilkPackage.PRINT_STATEMENT:
			sw = new PrintStatementWrap((PrintStatement) e);
			break;
		case SilkPackage.INVOCATION:
			sw = new InvocationWrap((Invocation) e);
			break;
		case SilkPackage.RETURN_STATEMENT:
			sw = new ReturnStatementWrap((ReturnStatement) e);
			break;
		default:
			break;
		}
		return sw;
	}

	public static ValueItem valueItem(ValueItem e) {
		ValueItem cw = null;
		EClass eClass = e.eClass();
		int classifierID = eClass.getClassifierID();
		switch (classifierID) {
		case SilkPackage.LITERAL:
			cw = new LiteralWrap((Literal) e);
			break;
		default:
			if (e instanceof Expression) {
				Expression exp = (Expression) e;
				cw = expression(exp);
			}
			break;
		}
		return cw;
	}
	
	public static Variable variable(Variable variable) {
		return new VariableWrap(variable);
	}

	public static Method method(Method method) {
		return new MethodWrap(method);
	}

	public static VariableRef variableRef(VariableRef variable) {
		return new VariableRefWrap(variable);
	}

	public static Program program(Program program) {
		return new ProgramWrap(program);
	}
}
